﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ItemLoadThreadManager.cs" company="SmartPlan">
//   SmartPlan 2011
// </copyright>
// <summary>
//   Defines the ItemLoadThreadManager type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DbDiff.WinClient.Helper
{
    /// <summary>
    /// The item load thread manager.
    /// </summary>
    public class ItemLoadThreadManager : ThreadManager
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ItemLoadThreadManager"/> class.
        /// </summary>
        /// <param name="formThread">
        /// The form thread.
        /// </param>
        /// <param name="workerThread">
        /// The worker thread.
        /// </param>
        public ItemLoadThreadManager(FormThread formThread, ItemLoadThread workerThread)
            : base(formThread, workerThread)
        {
            workerThread.OnStart   += this.OnStart;
            workerThread.OnFinish  += this.OnFinish;
            workerThread.OnSuccess += this.OnSuccess;
            workerThread.OnFailed  += this.OnFailed;
        }

        #endregion Constructors

        #region Event handlers 

        /// <summary>
        /// The on start.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event arguments
        /// </param>
        private void OnStart(object sender, WorkerThreadEventArgs e) 
        {
            ((StatusFormThread)this._formThread).SetEventStatus(e.EventStatusId, e.State, e.Result);
        }

        /// <summary>
        /// The on finish.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event arguments
        /// </param>
        private void OnFinish(object sender, WorkerThreadEventArgs e) 
        {
            ((StatusFormThread)this._formThread).SetEventStatus(e.EventStatusId, e.State, e.Result);
        }

        /// <summary>
        /// The on success.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event arguments
        /// </param>
        private void OnSuccess(object sender, WorkerThreadEventArgs e) 
        {
            ((StatusFormThread)this._formThread).SetEventStatus(e.EventStatusId, e.State, e.Result);
        }

        /// <summary>
        /// The on failed.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event arguments
        /// </param>
        private void OnFailed(object sender, WorkerThreadEventArgs e) 
        {
            ((StatusFormThread)this._formThread).SetEventStatus(e.EventStatusId, e.State, e.Result);
        }

        #endregion Event handlers 

    }
}